package day03pm;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * @author JokerQ
 * @date 2020/8/25 - 13:03
 */
public class Server_v5 {
    public static void main(String[] args) {
        try {
            System.out.println("服务端启动！！！");
            ServerSocket serverSocket = new ServerSocket(8888);
            Socket socket = serverSocket.accept();
            System.out.println("一个客户端连接了...");
            InputStream is = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(is, "utf-8");
            BufferedReader reader = new BufferedReader(isr);
            OutputStream out = socket.getOutputStream();
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(out,"utf-8"),true);
            while(true){
                String str = reader.readLine();
                System.out.println("收到客户端发来："+str);
               writer.println(str+"\t["+
                        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"]");
                writer.flush();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

